Ext.define('com.hh.global.SimpleFormPanelWindow', {
	extend : 'com.hh.base.BaseWindow',
	object : {},
	entityKey : 'id',
	modal : true,
	afinit : function() {
		var panel = this.panel;
		var config = this.config;
		panel.add(this.createFormPanel());
		if (!Util.isNull(config.parentRecord)) {
			this.loadData(config.parentRecord.get(this.entityKey),
					config.parentRecord);
		} else if (config.objectId) {
			this.loadData(config.objectId);
		}
	},
	editAction : 'findObjectById',
	loadData : function(id, parentRecord) {
		var page = this;
		Request.request(this.action + this.editAction, {
			id : id,
			orgids : parentRecord.get('vorgid'),
			vcreates : parentRecord.get('vcreate')
		}, function(object) {
			page.object = object;
			FormPanel.setValues(page.form, page.object);
			page.afDataLoad();
		});
	},
	afDataLoad : function() {
	},
	getToolBarByType : function(type) {
		if (type == 'cancel') {
			return {
				iconCls : 'cancel',
				text : '重置表单',
				handler : function() {
					this.up('form').getForm().reset();
				}
			};
		}
	},
	toolBarItems : [],
	getToolBarItems : function() {
		this.toolBarItems.push('->');
		this.toolBarItems.push(this.getToolBarByType('cancel'));
		return this.toolBarItems;
	},
	getToolbar : function() {
		return null;
		// Ext.create('com.hh.base.BaseToolbar', {
		// items : this.getToolBarItems()
		// });
	},
	closeEvent : function(panel) { // window关闭事件
		if (panel.config.callbackRefresh) {
			panel.config.callbackRefresh();
		}
	},
	submitForm : function() {
		var bereturn = this.bfSubmitForm();
		if (bereturn != false) {
			FormPanel.submit(this.form);
		}
	},
	bfSubmitForm : function() {
		return true;
	},
	getBtnByType : function(type) {
		var page = this;
		if ("save" == type) {
			return {
				iconCls : 'yes',
				text : '保    存',
				handler : function() {
					page.submitForm();
				}
			};
		} else if ("cancel" == type) {
			return {
				iconCls : 'cancel',
				text : '取    消',
				handler : function() {
					page.close();
				}
			};
		}
	},
	getBtns : function() {
		return [ this.getBtnByType("save"), this.getBtnByType("cancel") ];
	},
	submitMethod : 'save',
	createFormPanel : function() {
		var page = this;
		this.form = Ext.create('com.hh.base.BaseFormPanel', {
			tbar : this.getToolbar(),
			url : this.action + this.submitMethod,
			items : this.getFormItems(),
			buttons : page.getBtns()
		});
		return this.form;
	}
});